<template>
  <div>
    <el-col>
      <el-menu router>
        <el-menu-item index="orderManager">
          <span class="sp2">
            <el-icon><DocumentCopy /></el-icon>
          </span>
          <span>订单管理</span>
        </el-menu-item>
      </el-menu>
    </el-col>
    <div class="tab-titles">
      <div
        class="box1"
        v-for="(title, index) in titles"
        :key="index"
        :class="{ active: selectedIndex === index }"
        @click="selectTab(index)"
      >
        {{ title }}
      </div>
    </div>
    <div class="tab-content">
      <div v-if="selectedIndex === 0">
        <el-table :data="tableData1" style="width: 100%">
          <el-table-column prop="orderCode" label="订单号" width="180" />
          <el-table-column prop="orderName" label="课程名称" width="180" />
          <el-table-column prop="orderPrice" label="课程价格" />
          <el-table-column prop="" label="实收价格" width="180" />
          <el-table-column prop="info" label="优惠信息" width="180" />
          <el-table-column prop="address" label="户主信息" />
          <el-table-column prop="buyerMsg" label="买家信息" width="180" />
          <el-table-column prop="sellerMsg" label="卖家信息" width="180" />
          <el-table-column prop="state" label="订单状态">
            <el-button type="danger">待付款</el-button>
          </el-table-column>
          <el-table-column prop="orderOperation" label="操作" width="180">
            <el-icon><EditPen /></el-icon>
            <el-button type="primary">操作</el-button>
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination
          v-model:page-size="pageSize"
          v-model:current-page="page"
          layout="prev, pager, next, jumper, sizes"
          :total="total"
        />
      </div>

      <div v-if="selectedIndex === 1">
        <el-table :data="tableData2" style="width: 100%">
          <el-table-column prop="orderCode" label="订单号" width="180" />
          <el-table-column prop="orderName" label="课程名称" width="180" />
          <el-table-column prop="orderPrice" label="课程价格" />
          <el-table-column prop="realPrice" label="实收价格" width="180" />
          <el-table-column prop="info" label="优惠信息" width="180" />
          <el-table-column prop="address" label="户主信息" />
          <el-table-column prop="buyerMsg" label="买家信息" width="180" />
          <el-table-column prop="sellerMsg" label="卖家信息" width="180" />
          <el-table-column prop="state" label="订单状态">
            <el-button type="success">已付款</el-button>
          </el-table-column>
          <el-table-column prop="trainingProgress" label="培训进度" width="180">
            <el-icon><View /></el-icon>
            <el-button type="primary">培训进度</el-button>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { orderIng, orderEd } from '../../api/order'
export default {
  name: 'OrderManager',
  data () {
    return {
      titles: ['待付款', '已完成'],
      selectedIndex: 0,
      tableData1: [],
      tableData2: [],
      // 分页参数
      page: 1,
      pageSize: 10,
      total: 0
    }
  },
  methods: {
    selectTab (index) {
      this.selectedIndex = index
    },
    orderI () {
      orderIng({
        page: this.page,
        pageSize: this.pageSize
      }).then((res) => {
        if (res.data.code === 200) {
          console.log(res)
          this.tableData1 = res.data.data.lists
          this.total = res.data.data.total
        }
      })
    },
    orderE () {
      orderEd().then((res) => {
        if (res.data.code === 200) {
          console.log(res)
          this.tableData2 = res.data.data
        }
      })
    }
  },
  watch: {
    // 监听当前页 和 一页多少条  重新请求列表
    page () {
      this.orderI()
    },
    pageSize () {
      this.orderI()
    }
  },
  created () {
    this.orderI()
    this.orderE()
  }
}
</script>

<style lang="scss" scoped>
.tab-titles {
  display: flex;
  .box1 {
    width: 100px;
    height: 45px;
    line-height: 36px;
    text-align: center;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
    font-weight: 900;
  }
}
.active {
  background-color: #fff;
  color: #0f85c9;
}
.el-pagination {
  margin-top: 25px;
  float: right;
}
.sp2{
  color: #ffd04b;
}
.el-col {
  margin-bottom: 25px;
}
</style>
